// pages/leaseOrder/leaseOrder.js
import Dialog from '@vant/weapp/dialog/dialog';
const http = require("../../api/camp")
import {
  leaseUserIdList,
  baseURL,
} from "../../api/my"
Page({

  /**
   * 页面的初始数据
   */
  data: {
    leaseUserId: [],     // 租赁订单商品数据列表
    leaseUserIdList: [], // 获取租赁订单列表数据
    baseURL,
    userId: wx.getStorageSync("userInfo")["userId"],
    right: 65,
    orderId: "",
  },

  // 租赁订单取消
  delLeaseOrder(event) {
    // console.log("event", event)
    // console.log("租赁订单取消order：", event.currentTarget.dataset.index)
    // 在 event 中获取页面中传过来的 data-index="{{item.orderId}}" 将 orderId 赋值给接口传到后端
    let orderId = event.currentTarget.dataset.index
    Dialog.confirm({
        title: '取消订单',
        message: '确定取消该订单吗？',
      })
      // console.log("租赁订单取消order：", order)
      .then(() => {
        // console.log("租赁订单取消order：", order)
        http.DelLeaseOrder(orderId).then(res => {
          if (res.code == 200) {
            this.getLeaseUserIdList()
          }
        })
      })
      .catch(() => {
        // on cancel
      });
  },

   // 获取租赁订单列表数据
  getLeaseUserIdList() {
    leaseUserIdList(this.data.userId).then(res => {
      if (res.code == 200 && res.data) {
        this.setData({
          leaseUserIdList: res.data,
        })
      }
      // console.log("获取租赁订单列表数据", res.data);
    })
  },

  goCampDetail(e) {
    //跳转页面+传递参数
    console.log("跳转到订单详情");
    let orderId = e.currentTarget.dataset.orderId;
    console.log("goCampDetail orderId", orderId)
    // 跳转到详情页面时将 orderId 传入过去
    wx.navigateTo({
      url: `/pages/leaseOrderDetail/leaseOrderDetail?orderId=${orderId}`,
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.getLeaseUserIdList()
  },
  onShow() {
    this.getLeaseUserIdList()
  }
})